/**
 * Created by Administrator on 2017/5/10 0010.
 */
checkCookie()
var mid= $.cookie('mid')
var token= $.cookie('token')
var money=$('.money span').html()
getData({url:balance,data:{mid:mid,token:token,money:money}}, function (data) {
        var html=template('money',data);
        $('.money').html(html)
})

$('.footer').on('touchstart', function () {
    var cash=$('input').val();
    console.log(cash)
    if(cash<1){

        $('.error').html('金额不得小于1')
        $('.error').show();
        $('input').val()
        return false
    }
    getData({url: balance, data: {mid: mid, token: token,money:cash}}, function (data) {
        if (data.state) {
            onBridgeReady(data.payconfig);
            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                }
            } else {
                onBridgeReady();
            }
        } else {

            alert(data.msg);
        }

    })
})
    function onBridgeReady(config) {
        if (typeof WeixinJSBridge === 'undefined') {
            alert('请在微信页打开页面！');
            return false;
        }
        WeixinJSBridge.invoke('getBrandWCPayRequest', config, function (res) {
            switch (res.err_msg) {
                case 'get_brand_wcpay_request:cancel':
                    alert('用户取消支付！');
                    history.go(-1);
                    break;
                case 'get_brand_wcpay_request:fail':
                    alert('支付失败！（' + res.err_desc + '）');
                    break;
                case 'get_brand_wcpay_request:ok':
                    //跳转成功页
                    window.location.href = 'ok.html';
                    break;
                default:
                    alert(JSON.stringify(res));
                    break;
            }
        })

    }

